package com.atguigu.day16.work;

public class Work3{
    public static void main(String[] args) {
        String[]arr={"a","b","c","d","e","f","g","h"};
        System.out.println(Change.binarySearch(arr,"g"));
    }
}
class Change {
    static public int binarySearch(String[] intsArray,String des){
        int left=0;
        int right=intsArray.length-1;
        int mid =(left+right)/2;
        while (left<=right){
            if (des.equals(intsArray[mid])){
                return mid;
            }else if(des.compareTo(intsArray[mid])>0){
                left=mid+1;
            }else{
                right=mid-1;
            }
            mid =(left+right)/2;
        }
        return -1;
    }
}

